package com.study.redis.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author flwu
 * @date 2020/3/19 6:49 PM
 * @MOTTO 保持空杯和敬畏
 */
@Service
public class RedisService {

    @Autowired
    private RedisTemplate redisTemplate;

    public boolean setRedis() {
        try {
            redisTemplate.opsForValue().set("name", "wufaliang");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

    public String getRedis() {
        String name = "";
        try {
            name = redisTemplate.opsForValue().get("name").toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return name;
    }

}
